import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/home/detail/page/cook_detail_page.dart';
import 'package:flutter_douban/model/cook_info_model.dart';

class CookItemCell extends StatelessWidget {
  final CookInfoModel model;
  const CookItemCell({Key? key, required this.model}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> widgetList = [];
    widgetList.add(Container(
        color: Colors.white,
        child: ClipRRect(
          child: CachedNetworkImage(
            imageUrl: model.img!,
            fit: BoxFit.cover,
            width: 150,
            height: 150 * 0.7,
          ),
          borderRadius: BorderRadius.circular(4),
        )));

    if(model.videoUrl?.isNotEmpty == true){
      /// 视频
      widgetList.add(
          Positioned(
            bottom: 8,
            right: 5,
            child: Image.asset(
              'assets/images/common/cell_video_play@2x.png',
              width: 32,
              height: 32,
              color: Colors.blueAccent,
            ),
          )
      );
    }

    return InkWell(
      child: Container(
        color: Colors.white,
        padding: EdgeInsets.only(left: 15, right: 15, top: 15),
        child: Row(
          children: [
            Stack(
              children: widgetList,
            ),
            SizedBox(
              width: 15,
            ),
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  width: MediaQuery.of(context).size.width - 200,
                  child: Text(
                    model.n!,
                    maxLines: 2,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 15,
                      color: AppColors.black,
                    ),
                  ),
                ),
                SizedBox(
                  height: 15,
                ),
                Container(
                  height: 18,
                  width: 46,
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                    color: AppColors.line,
                    borderRadius: BorderRadius.all(Radius.circular(3)),
                  ),
                  child: Text(
                    '详细内容',
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      fontSize: 10,
                      color: AppColors.qianTextColor,
                    ),
                  ),
                ),
                SizedBox(
                  height: 15,
                ),
                Row(
                  children: [
                    ClipRRect(
                      child: CachedNetworkImage(
                        imageUrl: model.nickIcon == null
                            ? model.a!.p!
                            : model.nickIcon!,
                        fit: BoxFit.cover,
                        width: 16,
                        height: 16,
                      ),
                      borderRadius: BorderRadius.circular(15),
                    ),
                    SizedBox(
                      width: 6,
                    ),
                    Text(
                      model.nickName == null ? model.a!.n! : model.nickName!,
                      overflow: TextOverflow.ellipsis,
                      style: TextStyle(
                        fontSize: 13,
                        color: AppColors.qianTextColor,
                      ),
                    )
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
      onTap: () {
        Navigator.of(context).push(MaterialPageRoute(builder: (_) {
          if (model.cook_id == null) {
            return CookDetailPage(id: model.id!);
          } else {
            return CookDetailPage(id: model.cook_id!);
          }
        }));
      },
    );
  }
}
